package com.yoomiito.app.base;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.yoomiito.app.Constant;
import com.yoomiito.app.model.bean.UserInfo;
import com.yoomiito.app.utils.UserInfoConfig;

import cn.droidlover.xdroidmvp.cache.SharedPref;

public class CurrentUser implements Parcelable {
    public UserInfo mUserInfo;
    private int companyId = -1;
    private int roleId = -1;
    private String inviteUrl;
    private String token;

    public String getToken() {
        if (TextUtils.isEmpty(token)){
            return SharedPref.getInstance(App.getInstance()).getString(Constant.TOKEN,"");
        }
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public int getCompanyId() {
//        if (companyId==-1){
//            companyId = UserInfoConfig.getCompanyId();
//        }
        return companyId;
    }

    public void setCompanyId(int companyId) {
        this.companyId = companyId;
    }

    public int getRoleId() {
//        if (roleId==-1){
//            roleId = UserInfoConfig.getRoleId();
//        }
        return roleId;
    }

    public void setRoleId(int roleId) {
        this.roleId = roleId;
    }

    public String getInviteUrl() {
        return inviteUrl;
    }

    public void setInviteUrl(String inviteUrl) {
        this.inviteUrl = inviteUrl;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeSerializable(this.mUserInfo);
        dest.writeInt(this.companyId);
        dest.writeInt(this.roleId);
        dest.writeString(this.inviteUrl);
        dest.writeString(this.token);
    }

    public CurrentUser() {
    }

    protected CurrentUser(Parcel in) {
        this.mUserInfo = (UserInfo) in.readSerializable();
        this.companyId = in.readInt();
        this.roleId = in.readInt();
        this.inviteUrl = in.readString();
        this.token = in.readString();
    }

    public static final Creator<CurrentUser> CREATOR = new Creator<CurrentUser>() {
        @Override
        public CurrentUser createFromParcel(Parcel source) {
            return new CurrentUser(source);
        }

        @Override
        public CurrentUser[] newArray(int size) {
            return new CurrentUser[size];
        }
    };
}
